package com.ruoyi.scrball.controller;


import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.scrball.domain.ScrbAll;
import com.ruoyi.scrball.service.IScrbAllService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;


/**
 * 生产日报总表Controller
 *
 * @author 汪洋
 * @date 2022-09-22
 */
@RestController
@RequestMapping("/scrball/all")
public class ScrbAllController extends BaseController {
    @Autowired
    private IScrbAllService scrbAllService;

    /**
     * 查询生产日报总表列表
     */
    @PreAuthorize("@ss.hasPermi('scrball:all:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScrbAll scrbAll) {
        startPage();
        List<ScrbAll> list = scrbAllService.selectScrbAllList(scrbAll);
        return getDataTable(list);
    }

    /**
     * 导出生产日报总表列表
     */
    @PreAuthorize("@ss.hasPermi('scrball:all:export')")
    @Log(title = "生产日报总表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScrbAll scrbAll) {
        List<ScrbAll> list = scrbAllService.selectScrbAllList(scrbAll);
        ExcelUtil<ScrbAll> util = new ExcelUtil<ScrbAll>(ScrbAll.class);
        util.exportExcel(response, list, "生产日报总表数据");
    }

    /**
     * 下载生产日报总表列表
     */
    @PreAuthorize("@ss.hasPermi('scrball:all:export')")
    @Log(title = "生产日报总表", businessType = BusinessType.EXPORT)
    @PostMapping("/download")
    public void download(HttpServletResponse response, ScrbAll scrbAll) {
        //List<ScrbAll> list = scrbAllService.selectScrbAllList(scrbAll);
        //ExcelUtil<ScrbAll> util = new ExcelUtil<ScrbAll>(ScrbAll.class);
        //util.exportExcel(response, list, "生产日报总表数据");
        scrbAllService.downloadScrbAll(response,scrbAll);
    }

    /**
     * 获取生产日报总表详细信息
     */
    @PreAuthorize("@ss.hasPermi('scrball:all:query')")
    @GetMapping(value = "/{cDate}")
    public AjaxResult getInfo(@PathVariable("cDate") String cDate) {
        return AjaxResult.success(scrbAllService.selectScrbAllByCDate(cDate));
    }

    /**
     * 新增生产日报总表
     */
    @PreAuthorize("@ss.hasPermi('scrball:all:add')")
    @Log(title = "生产日报总表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScrbAll scrbAll) {
        return toAjax(scrbAllService.insertScrbAll(scrbAll));
    }

    /**
     * 修改生产日报总表
     */
    @PreAuthorize("@ss.hasPermi('scrball:all:edit')")
    @Log(title = "生产日报总表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScrbAll scrbAll) {
        return toAjax(scrbAllService.updateScrbAll(scrbAll));
    }

    /**
     * 删除生产日报总表
     */
    @PreAuthorize("@ss.hasPermi('scrball:all:remove')")
    @Log(title = "生产日报总表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cDates}")
    public AjaxResult remove(@PathVariable String[] cDates) {
        return toAjax(scrbAllService.deleteScrbAllByCDates(cDates));
    }
}
